<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>抱抱堂-摇摇乐</title>
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="{:C('IMG_PATH')}static/css/main.css?v=12">
</head>
<body class="linear-bg">
<div class="main" style="opacity:1;top:20px;">
    <section class="gift card">
        <div class="brief_title">
            <h5>{$cardDetail.card_name}</h5>
            <p>{$cardDetail.winning_time}</p>
        </div>
        <section class="brief_content">
            <p>{$cardDetail.card_intro}</p>
        </section>
        <section class="gift_personal_info">
            <form name="" method="post" class="form_profile">
            <input type="hidden" name="card_num" value={$cardDetail.card_num} />
            <input type="hidden" name="card_id" value={$cardDetail.id} />
            <p><input type="password" name="key" placeholder="核销密码" /></p>
            <p class="captcha_box">
                <input name="verify" type="text" placeholder="验证码" class="input_verify" />
                {:sp_verifycode_img('length=4&font_size=20&width=180&height=42&use_noise=1&use_curve=0','style="cursor: pointer;" title="点击获取"')}
            </p>
            <section class="gift_btn">
                <button class="long-yellow-btn">核销</button>
            </section>
            </form>
        </section>
    </section>
</div>
<footer class="white"><img src="{:C('IMG_PATH')}static/img/logo_white.png" /></footer>
</body>
<script src="{:C('IMG_PATH')}static/js/zepto.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    (function(){
        $(".form_profile").on('submit', function(e){
            e.preventDefault();
            var formstr = $(".form_profile").serialize();
            $.ajax({
                url : "{:U('Portal/OpenApi/cardVerification')}",
                cache : false,
                type : "POST",
                dataType : "json",
                data : formstr,
                success : function(msg, textStatus){
                    if (msg.errcode == 0) {
                        if (msg.data.status == 0) {
                            alert('核销成功');
                            wx.closeWindow();
                        } else if (msg.data.status == 1){
                            alert('参数异常');
                        } else if (msg.data.status == 2){
                            alert('无效的卡券');
                        } else if (msg.data.status == 3){
                            alert('核销密码错误');
                        } else if (msg.data.status == 4){
                            alert('核销失败');
                        } else if (msg.data.status == 5){
                            alert('验证码错误');
                            var captcha_img = $(".captcha_box img");
                            $(".captcha_box img").prop('src', captcha_img.attr('src') + '&t=1');
                            $("input.input_verify").prop('value', '');
                        }
                        return false;
                    } else {
                        alert('核销失败，请稍后重试');
                        return false;
                    }
                },
                error : function(){
                    alert('核销失败，请稍后重试');
                    return false;
                }
            });
        });
    })();
</script>
</html>